package com.hq.fxh.No5_User.MyModle;

import android.support.v4.view.PagerAdapter;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;

/**
 * @author 大圣
 * @ClassName AdPagerAdapter
 * @Description :
 * @Created 2015/11/19 0019
 * @Email qwqe601660957@163.com
 */
public abstract class AdPagerAdapter extends PagerAdapter {
    private SparseArray<View> views = new SparseArray<>();

    @Override
    public int getCount() {
        return 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = views.get(position);
        view = getView(position, view, container);
        views.put(position, view);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = (View) object;
        container.removeView(view);
        views.remove(position);
    }

    public void removeView(int position) {
        views.remove(position);
    }

    public abstract View getView(int position, View convertView, ViewGroup container);

    public View getView(int position) {
        return views.get(position);
    }
}
